
<!DOCTYPE html >
<html>
<head>
    <base>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>药品审核</title>
    <link rel="stylesheet" href="/res/layui/css/layui.css" media="all">
    <script type="text/javascript" src="/res/js/jquery-3.4.1.min.js"></script>
    <script type="text/javascript" src="/res/js/util.js"></script>
    <script type="text/javascript" src="/ok-admin/js/permissionSetting.js"></script>
    <!--模糊搜索区域-->
    <link rel="stylesheet" href="../../css/oksub.css">
    <style>
        body{margin: 10px;}
        .demo-carousel{height: 300px; line-height: 300px; text-align: center;}

        #addReload {
            position: absolute;
            top: 0%;
            z-index: 10000;
            background: rgb(0, 0, 0, 0.9);
            width: 100%;
            height: 100%;
            display: none;
        }

        #addOperation {
            position: absolute;
            left: 30%;
            top: 15%;
            width: 40%;
            background: white;
        }
        .layui-form-select .layui-edge{
            margin-top: 13px;
        }
    </style>
</head>
<body>
<!--当前状态 根据状态定职位-->
<input type="hidden" name="status" id="status">
<div class="ok-body">
    <!--模糊搜索区域-->
    <div class="layui-row">
        <form class="layui-form layui-col-md12 ok-search">
            <input type="text" name="drugName" id="drugName" placeholder="请输入药品名称" autocomplete="off"
                   class="layui-input">
            <div class="layui-inline" style="margin-left: 10px;">
                <div class="layui-input-inline">
                    <select name="isva"  lay-search="">
                        <option value="">选择按钮类型</option>
                        <option value="20">待审核</option>
                        <option value="60">总公司总经理通过</option>
                        <option value="61">总公司总经理不通过</option>
                    </select>
                </div>
            </div>
            <button class="layui-btn" lay-submit="" lay-filter="search">
                <i class="layui-icon layui-icon-search"></i>
            </button>

        </form>
    </div>
    <!--数据表格-->
    <table class="layui-hide" id="goods" lay-filter="demo"></table>
</div>
<script type="text/html" id="xx">
    <a class="layui-btn layui-btn-xs" lay-event="chakan" id="dindanxx">查看配置材料</a>
    <a class="layui-btn layui-btn-xs" lay-event="HqReview">查询审核详情</a>
</script>

<script src="/res/layui/layui.js" charset="utf-8"></script>
<script type="text/html" id="barDemo">
    {{# if(returnUser()){ }}
        {{# if(authorization("audit:managerAudit") ){ }}
            {{# if(d.isva<60){ }}
                <a class="layui-btn layui-btn-danger layui-btn-xs" onclick="openAudit('60')" lay-event="audit" >审核</a>
            {{# }else{ }}
                <button class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" disabled>审核</button>
            {{# } }}
        {{# }else if(authorization("audit:sellAudit")){ }}
            <button class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" disabled>审核</button>
        {{# }else{ }}
            <button class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" disabled>审核</button>
        {{# } }}
    {{# }else{ }}
        <button class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" disabled>审核</button>
    {{# } }}
</script>
<script type="text/html" id="tu">
    <img src="{{ d.images }}" alt="图片" id="dd" width="50" height="50"  onclick="previewImg(this)">
</script>
<script>
    var openIndex = null;
    layui.use(['laydate','form', 'laypage', 'layer', 'table', 'upload', 'element'], function(){
        var laydate = layui.laydate //日期
            ,laypage = layui.laypage //分页
        layer = layui.layer //弹层
            ,table = layui.table //表格
            ,upload = layui.upload //上传
            ,form=layui.form
            ,element = layui.element; //元素操作

        //监听Tab切换
        element.on('tab(demo)', function(data){
            layer.msg('切换了：'+ this.innerHTML);
            console.log(data);
        });
        //执行一个 table 实例
        let roleTable = table.render({
            elem: '#goods'
            , url: '/hqDrug/selectAllTwo'
            , title: '药品管理表'
            // ,size:'sm'
            ,height: 'full-200', cellMinWidth: 80 //最大化适应
            ,height:600
            , cols: [[
                // {type: 'checkbox', fixed: 'left',width:50}
                {field: 'drugName', title: '药品名称', width: 140, fixed: 'left', unresize : true, sort: true,align:"center"}
                , {field: 'typeName', title: '药品类型', align:"center"}
                , {field: 'drugRetail', title: '零售价', width: 120,align:"center"}
                , {field: 'drugWho', title: '批发价', width: 120, sort: true,align:"center"}
                , {field: 'drugOut', title: '出库价', width: 120,align:"center"}
                , {field: 'isva', title: '药品状态', width: 220, templet: "#typeTpl",align:"center", unresize : true}
                , {field: 'images', title: '图片',width: 120, templet: "#tu",align:"center"}
                , {fixed: 'right',title: '查询信息', width: 210, align:'center', toolbar: '#xx',align:"center"}
                , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 140, fixed: 'right',align:"center"}
            ]]
            , page: true
            , id: 'testReload'
            , where: { //过滤药品状态为0,10
                status: '0,10'
            }
        });

        //监听工具条
        table.on('tool(demo)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                ,layEvent = obj.event; //获得 lay-event 对应的值
            console.info(data);
            if(obj.event === 'audit'){ //审核
                console.info(data)
                var id = data.drugId;
                //将采购单id赋值
                $("#purchaseId").val(id);
                //获取所点击审核的人的权限
                let status = $("#status").val();
                console.info($("#status").val());
                openIndex = layui.layer.open({
                    type: 2,
                    area: ['55%', '60%'], //宽高
                    title: '审核信息',
                    shift:1,//弹出框动画效果
                    skin: 'layui-layer-molv',//样式
                    shadeClose:true,//点击也能遮罩层关闭
                    shade: [0.8, '#393D49'] ,//显示遮罩
                    maxmin: true, //开启最大化最小化按钮
                    // content:  $("#popUpdateTest"),
                    content:`/ok-admin/pages/audit/auditForm.html?id=${id}&status=${status}&audit=drug`
                });
            } else if(layEvent==='chakan'){ //查看配置材料
                var drugId=data.drugId;
                var url="/ok-admin/pages/hqDrug/drugMatRead.html?id="+drugId;
                layer.open({
                    type: 2,
                    title: '配置材料',
                    shadeClose:true,//点击也能遮罩层关闭
                    skin: 'layui-layer-molv',//样式
                    shade: [0.8, '#393D49'] ,//显示遮罩
                    area : ['76%' , '75%'],//弹出框大小
                    maxmin: true, //开启最大化最小化按钮
                    shift:1,//弹出框动画效果
                    content: [url,'on'] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                });
            }else if(obj.event === "HqReview"){ //审核记录
                var id = data.drugId;
                openIndex = layer.open({
                    type: 2,
                    skin: 'layui-layer-molv',//样式
                    shadeClose:true,//点击也能遮罩层关闭
                    shade: [0.8, '#393D49'] ,//显示遮罩
                    area: ['85%', '85%'], //宽高
                    title: '审核记录',
                    maxmin: true, //开启最大化最小化按钮
                    content: '/ok-admin/pages/audit/auditList.html?marketId='+id //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                });
            }
        });



        //查询条件
        form.on("submit(search)", function (data) {
            console.info(data)
            roleTable.reload({
                where: data.field,
                page: {curr: 1}
            });
            console.log("0000")
            return false;
        });
        //审核请求
        window.openAudit = function (status) {
            $("#status").val(status);
        }
    });
    /**
     * 关闭弹出页面并提示
     */
    function closeOpen(msg) {
        //语音播放
        playMessage(msg);
        layer.close(openIndex);
        layer.msg(msg, {time: 1100,icon:1}, function () {
            table.reload("testReload");
        });
    }

    /**
     * 错误提示 关闭弹出层
     */
    function errorCloseOpen(msg){
        //语音播放
        playMessage(msg);
        layer.close(openIndex);
        layer.msg(msg,{time:2000,icon:2},function(){
            table.reload("testReload");
            //window.location.reload(true);
        });
    }

    /**
     * 图片预览
     */
    function previewImg(obj) {
        var img = new Image();
        img.src = obj.src;
        var height = img.height + 50; //获取图片高度
        var width = img.width; //获取图片宽度
        var imgHtml = "<img src='" + obj.src + "' />";
        //弹出层
        layer.open({
            type : 1,
            shade : 0.8,
            offset : 'auto',
            area : [ width + 'px', height + 'px' ],
            shadeClose : true,//点击外围关闭弹窗
            scrollbar : false,//不现实滚动条
            title : "图片预览", //不显示标题
            content : imgHtml, //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
            cancel : function() {
                //layer.msg('捕获就是从页面已经存在的元素上，包裹layer的结构', { time: 5000, icon: 6 });
            },
            time : 2000
            //2s后自动关闭
        });
    }

</script>
<script type="textml" id="typeTpl">
    {{#  if(d.isva == 20){ }}
        <p class="layui-btn layui-btn-danger layui-btn-xs">待审核</p>
    {{#  } else if(d.isva == 60){ }}
        <p class="layui-btn layui-btn-warm layui-btn-xs">总公司总经理通过,完成审核</p>
    {{#  } else if(d.isva == 61){ }}
        <p class="layui-btn layui-btn-danger layui-btn-xs">总公司总经理不通过</p>
    {{#  } }}
</script>
</body>
</html>